package com.mxx.bu_yang.adapter;

import android.app.Activity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.mxx.bu_yang.R;
import com.mxx.bu_yang.response.HomeMenuResponse;

import org.jetbrains.annotations.NotNull;

import me.jessyan.autosize.utils.ScreenUtils;

/**
 * 作者：刘江飞
 * 时间：2020/10/14  14:42
 * 邮箱：642371742Z@qq.com
 * 描述：
 **/
public class HomeMenuAdapter extends BaseQuickAdapter<HomeMenuResponse, BaseViewHolder> {
    private Activity activity;


    public HomeMenuAdapter(Activity activity, int layoutResId) {
        super(layoutResId);
        this.activity = activity;
        addChildClickViewIds(R.id.ll_menu);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, HomeMenuResponse response) {
        if (response == null) {
            return;
        }

        int[] screenSize = ScreenUtils.getScreenSize(activity);
        int screenWidth = screenSize[0];

        int widgetWidth = (screenWidth - 2 * 30) / 2;
        LinearLayout ll_menu = baseViewHolder.getView(R.id.ll_menu);
        ImageView iv_menu = baseViewHolder.getView(R.id.iv_menu);
        TextView tv_menu = baseViewHolder.getView(R.id.tv_menu);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.width = widgetWidth;
        params.height = widgetWidth;
        ll_menu.setLayoutParams(params);

        iv_menu.setImageDrawable(response.img_resource);
        tv_menu.setText(response.menu_name);
    }
}
